cmake_minimum_required(VERSION 3.14)

project(miniCompass3D)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_PREFIX_PATH $ENV{QTDIR})

find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)

set(LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/include")

# congrads lib
set(CONGRADS_LIB ${LIBRARIES}/congradstestapp/congrads/Debug)
set(CONGRADS_INCL  ${LIBRARIES}/congradstestapp/congrads/include)
include_directories(${CONGRADS_LIB})
include_directories(${CONGRADS_INCL})

IF(WIN32)
	add_library(congrads  SHARED IMPORTED)
	set_property(TARGET congrads PROPERTY IMPORTED_LOCATION ${CONGRADS_LIB}/congrads.dll)
	set_property(TARGET congrads PROPERTY IMPORTED_IMPLIB ${CONGRADS_LIB}/congrads.lib)
ENDIF()

file(GLOB_RECURSE SRC source/*.cpp source/*.h source/*.ui)

SET(PLANEITEMS source/Model/PlaneItems)
SET(MATH source/Service/Math)
SET(INTERFACES source/Model/Interfaces)
SET(UTILS source/Service/Utils)
SET(CANVAS source/Visuals/Canvas)
SET(DRAWABLES source/Visuals/Drawables)
SET(COMMANDS source/Service/Commands)
SET(INPUT_ source/Service/Input)
SET(CONTROLLERS source/Controllers)
SET(DRAWCOMMANDS source/Service/Commands/DrawCommands)
SET(SOLVERS source/Model/Solver)
SET(CONSTRAINTS source/Service/Constraints)
SET(QTWINDOWS source/Visuals/Qt)
SET(GEOMETRYVISUAL ${DRAWABLES}/GeometryVisuals)
SET(CONSTRAINTSVISUAL ${DRAWABLES}/ConstraintVisuals)
SET(OTHERVISUALS ${DRAWABLES}/OtherVisuals)

INCLUDE_DIRECTORIES(
	resources
)


INCLUDE_DIRECTORIES(
	${PLANEITEMS}
	${MATH}
	${INTERFACES}
	${UTILS}
	${CANVAS}
	${DRAWABLES}
	${COMMANDS}
	${INPUT_}
	${CONTROLLERS}
	${DRAWCOMMANDS}
	${SOLVERS}
	${CONSTRAINTS}
	${QTWINDOWS}
	${GEOMETRYVISUAL}
	${CONSTRAINTSVISUAL}
	${OTHERVISUALS}
)

set(PROJECT_SOURCES
    ${SRC}
)

add_executable(miniCompass3D
	${PROJECT_SOURCES}
)

target_link_libraries(miniCompass3D PRIVATE Qt${QT_VERSION_MAJOR}::Widgets congrads)

IF(WIN32)
	configure_file(${CONGRADS_LIB}/congrads.dll ${CMAKE_CURRENT_BINARY_DIR}/congrads.dll COPYONLY)
ENDIF()